{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import turtle as T\n",
    "import random\n",
    "import time\n",
    "\n",
    "# 画樱花的躯干(60,t)\n",
    "def Tree(branch, t):\n",
    "    time.sleep(0.0005)\n",
    "    if branch > 3:\n",
    "        if 8 <= branch <= 12:\n",
    "            if random.randint(0, 2) == 0:\n",
    "                t.color('snow')  # 白\n",
    "            else:\n",
    "                t.color('lightcoral')  # 淡珊瑚色\n",
    "            t.pensize(branch / 3)\n",
    "        elif branch < 8:\n",
    "            if random.randint(0, 1) == 0:\n",
    "                t.color('snow')\n",
    "            else:\n",
    "                t.color('lightcoral')  # 淡珊瑚色\n",
    "            t.pensize(branch / 2)\n",
    "        else:\n",
    "            t.color('sienna')  # 赭(zhě)色\n",
    "            t.pensize(branch / 10)  # 6\n",
    "        t.forward(branch)\n",
    "        a = 1.5 * random.random()\n",
    "        t.right(20 * a)\n",
    "        b = 1.5 * random.random()\n",
    "        Tree(branch - 10 * b, t)\n",
    "        t.left(40 * a)\n",
    "        Tree(branch - 10 * b, t)\n",
    "        t.right(20 * a)\n",
    "        t.up()\n",
    "        t.backward(branch)\n",
    "        t.down()\n",
    "\n",
    "# 掉落的花瓣\n",
    "def Petal(m, t):\n",
    "    for i in range(m):\n",
    "        a = 200 - 400 * random.random()\n",
    "        b = 10 - 20 * random.random()\n",
    "        t.up()\n",
    "        t.forward(b)\n",
    "        t.left(90)\n",
    "        t.forward(a)\n",
    "        t.down()\n",
    "        t.color('lightcoral')  # 淡珊瑚色\n",
    "        t.circle(1)\n",
    "        t.up()\n",
    "        t.backward(a)\n",
    "        t.right(90)\n",
    "        t.backward(b)\n",
    "\n",
    "# 绘图区域\n",
    "t = T.Turtle()\n",
    "# 画布大小\n",
    "w = T.Screen()\n",
    "t.hideturtle()  # 隐藏画笔\n",
    "t.getscreen().tracer(5, 0)\n",
    "w.screensize(bg='wheat')  # wheat小麦\n",
    "t.left(90)\n",
    "t.up()\n",
    "t.backward(150)\n",
    "t.down()\n",
    "t.color('sienna')\n",
    "\n",
    "# 画樱花的躯干\n",
    "Tree(60, t)\n",
    "# 掉落的花瓣\n",
    "Petal(200, t)\n",
    "w.exitonclick()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "language_info": {
   "name": "python"
  },
  "orig_nbformat": 4
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
